package net.skillkill.base;

import net.joke.base.render.SpriteObjectData;
import net.joke.base.systems.InputSystem;

import org.anddev.andengine.engine.camera.BoundCamera;
import org.anddev.andengine.entity.layer.tiled.tmx.TMXTiledMap;
import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

import com.artemis.Entity;

/**
 * Questa classe serve a mantenere tutte le risorse di AndEngine (quantomeno le textures)<br>
 * Funge anche da Factory per generare gli sprite necessari ai Renderable<br>
 * @author Gianluca
 *
 */
public class SkillKillRes {
	public static TMXTiledMap mTMXTiledMap;
	public static BoundCamera mBoundChaseCamera;
	
	public static BitmapTextureAtlas mTexturePlayer;
	public static TiledTextureRegion mPlayerTextureRegion;
	public static final int PLAYERSIZE = 32;

	public static BitmapTextureAtlas mTextureMinion01;
	public static TiledTextureRegion mMinion01TextureRegion;
	public static final int MINION01SIZE = 32;

	public static BitmapTextureAtlas mTextureBullet01;
	public static TiledTextureRegion mBullet01TextureRegion;
	public static final int BULLET01SIZE = 16;

	public static BitmapTextureAtlas mTextureExplosion01;
	public static TiledTextureRegion mExplosion01TextureRegion;
	public static final int EXPLOSION01SIZE = 32;
	
// sono in Res	
//	public static BitmapTextureAtlas mGreenFontTexture;
//	public static BitmapTextureAtlas mRedFontTexture;
//	public static Font mGreenFont;
//	public static Font mRedFont;
//	
//	public static Scene scene;
	
	public static AnimatedSprite playerSprite(Scene scene) {
		AnimatedSprite rv = new AnimatedSprite(0, 0, PLAYERSIZE, PLAYERSIZE, mPlayerTextureRegion);
		mBoundChaseCamera.setChaseEntity(rv);
		Rectangle mHealthBar = new Rectangle(0,-5,rv.getWidth(),3);
		mHealthBar.setColor(1,0,0);
		rv.attachChild(mHealthBar);
		scene.attachChild(rv);
		return rv;
	}

	
	// TODO Ricordarsi alla distruzione dello sprite di deregistrare la touch area.
	public static AnimatedSprite minion01Sprite(Scene scene) {
		AnimatedSprite rv = new AnimatedSprite(0, 0, MINION01SIZE, MINION01SIZE, mMinion01TextureRegion) {
			@Override
			public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
					float pTouchAreaLocalX, float pTouchAreaLocalY) {
				SpriteObjectData objData = ((SpriteObjectData)getUserData());
				return objData.inputSystem.onEntityTouched(objData.owner, pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
			}
		};
		Rectangle mHealthBar = new Rectangle(0,-5,rv.getWidth(),3);
		mHealthBar.setColor(1,0,0);
		rv.attachChild(mHealthBar);
		scene.attachChild(rv);
		scene.registerTouchArea(rv);
		return rv;
	}

	public static AnimatedSprite bullet01Sprite(Scene scene) {
		AnimatedSprite rv = new AnimatedSprite(0, 0, BULLET01SIZE, BULLET01SIZE, mBullet01TextureRegion);
		scene.attachChild(rv);
		rv.animate(100);
		return rv;
	}
	public static AnimatedSprite explosion01Sprite(Scene scene) {
		AnimatedSprite rv = new AnimatedSprite(0, 0, EXPLOSION01SIZE, EXPLOSION01SIZE, mExplosion01TextureRegion);
		scene.attachChild(rv);
		rv.animate(25, false);
		return rv;
	}

	
	
// Sono in Res	
//	public static Text greenText(Scene scene, float text, float x, float y) {
//		int tmp = (int)text;
//		return greenText(scene, String.valueOf(tmp), x, y);
//	}
//	public static Text greenText(Scene scene, String text, float x, float y) {
//		return text(scene, text, x, y, mGreenFont);
//	}
//	public static Text text(Scene scene, String text, float x, float y, Font font) {
//		Text rv = new Text(x, y, font, text);
//		scene.attachChild(rv);
//		return rv;
//	}
 	
}
